import { DynamicModule, Global, Module } from '@nestjs/common';
import { ImclientService } from './imclient.service';
import { HttpModule } from '@nestjs/axios';
import { ImclientConfig } from './type/config';

@Global()
@Module({
	imports: [HttpModule],
  providers: [ImclientService],
  exports: [ImclientService],
})
export class ImclientModule {
	static forRootAsync(options: {
		imports?: any[];
		useFactory: (...args: any[]) => Promise<ImclientConfig> | ImclientConfig;
		inject?: any[];
		}): DynamicModule {
		const providers = [
			{
			provide: 'IM_CONFIG',
			useFactory: options.useFactory,
			inject: options.inject || [],
			},
			ImclientService,
		];
	
		return {
			module: ImclientModule,
			providers: providers,
			exports: [ImclientService],
		};
	}
}
